home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_359 / dice / dice.lzh / lib / stdlib / atoi.c < prev    next >
C/C++ Source or Header  |  1990-04-01  |  442b  |  38 lines

  1.  
  2. /*
  3.  *  int ATOI(str)
  4.  *
  5.  *  (c)Copyright 1990, Matthew Dillon, All Rights Reserved
  6.  */
  7.  
  8. #include <stdlib.h>
  9.  
  10. long
  11. atol(str)
  12. const char *str;
  13. {
  14.     return(atoi(str));
  15. }
  16.  
  17. int
  18. atoi(str)
  19. const char *str;
  20. {
  21.     short neg = 0;
  22.     long v = 0;
  23.  
  24.     while (*str == ' ' || *str == '\t')
  25.     ++str;
  26.     if (*str == '-') {
  27.     neg = 1;
  28.     ++str;
  29.     }
  30.     while (*str >= '0' && *str <= '9')
  31.     v = v * 10 + *str++ - '0';
  32.     if (neg)
  33.     v = -v;
  34.     return(v);
  35. }
  36.  
  37.  
  38.